package bookManageSystem.dao;

import bookManageSystem.po.Admin;
import bookManageSystem.po.Doctor;

import java.awt.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;




    public class DoctorDAO {

        private static final String USER = "root";
        private static final String PASS = "123456";
        private static final String DB_URL = "jdbc:mysql://localhost:3306/huaide?useUnicode=true&characterEncoding=UTF-8";

        private Connection getConnection() throws SQLException {
            return DriverManager.getConnection(DB_URL, USER, PASS);
        }


        public List<Doctor> selectDoctorsByDepartment(String selectedDepartment) {
            List<Doctor> doctors = new ArrayList<>();
            String sql = "SELECT doctorId, name, gender, age, position, description, schedule, department FROM doctors WHERE department = ?";

            try (Connection conn = getConnection();
                 PreparedStatement pstmt = conn.prepareStatement(sql)) {

                pstmt.setString(1, selectedDepartment);

                try (ResultSet rs = pstmt.executeQuery()) {
                    while (rs.next()) {
                        Doctor doctor = new Doctor();
                        doctor.setDoctorId(rs.getInt("doctorId"));
                        doctor.setName(rs.getString("name"));
                        doctor.setGender(rs.getString("gender"));
                        doctor.setAge(rs.getInt("age"));
                        doctor.setPosition(rs.getString("position"));
                        doctor.setDescription(rs.getString("description"));
                        doctor.setSchedule(rs.getString("schedule"));
                        doctor.setDepartment(rs.getString("department"));
                        doctors.add(doctor);
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace(); // 生产环境中应使用日志记录
            }

            return doctors;
        }
    }



